<?php
class AllegroModel{
	private $subkategorie;
	
	const maxFileWeight = 1048576; // 1MB = 1048576;
	
#TODO kategorie

	protected function categoryLpUp($id_kategoria=null,$id_kategoria_parent=null){
		$q__ = "SELECT categLp,pcategID FROM ".ALLCATEG." WHERE categID = {$id_kategoria}";
		$curent_row = tools::__adodb('getRow',$q__,true,$this->db);
		$curent_lp__ = $curent_row['categLp'];
		$new_lp__ = $curent_lp__-1;
		if ($curent_lp__ > 1){
			if(tools::__adodb('exec',"UPDATE ".ALLCATEG." SET categLp={$curent_lp__} WHERE categLp = {$new_lp__} AND pcategID = {$id_kategoria_parent}",true,$this->db))
				tools::__adodb('exec',"UPDATE ".ALLCATEG." SET categLp={$new_lp__} WHERE categID = {$id_kategoria}",true,$this->db);
		}		
	}
	
	protected function categoryLpDown($id_kategoria=null,$id_kategoria_parent=null){
		$curent_row = tools::__adodb('getRow',"SELECT categLp  FROM ".ALLCATEG." WHERE categID = {$id_kategoria}",true,$this->db);
		$curent_lp__ = $curent_row['categLp'];
		$max_lp__ = tools::__adodb('getOne',"SELECT MAX(categLp) FROM ".ALLCATEG." WHERE pcategID = {$id_kategoria_parent} AND pageID = '{$this->pageID}'",true,$this->db);
		$new_lp__ = $curent_lp__+1;
		if ($curent_lp__ < $max_lp__ ){
			if(tools::__adodb('exec',"UPDATE ".ALLCATEG." SET categLp={$curent_lp__} WHERE categLp = {$new_lp__} AND  pcategID = {$id_kategoria_parent}",true,$this->db))
				tools::__adodb('exec',"UPDATE ".ALLCATEG." SET categLp={$new_lp__} WHERE categID = {$id_kategoria}",true,$this->db);
		}		
	}	
	protected function saveNewCategory(){
		global $config;
		$lp__ =  tools::__adodb('getOne',"SELECT Max(categLp) FROM ".ALLCATEG." 
			WHERE pcategID = ".tools::__mres($config->pcategID)." 
				AND pageID = '{$this->pageID}' AND  pageID = '{$this->pageID}'",true,$this->db);
		$lp__++;
		$q__ = "INSERT INTO ".ALLCATEG." (pageID,categID,pcategID, categLp, pageID) 
			VALUES (".tools::__mres($config->pageID).",NULL,".tools::__mres($config->pcategID).",".tools::__mres($lp__).",'{$this->pageID}')";
		tools::__adodb('exec',$q__,true,$this->db);
		
		$categID = $this->db->lastInsertId();
		if(is_array($config->categName)){
			foreach ($config->categName as $lang => $kateg) {
				$q__ = "INSERT INTO ".ALLCATLA." (categID,categLang,categName) 
					VALUES (".tools::__mres($categID).",'{$lang}',".tools::__mres($kateg).")";
				tools::__adodb('exec',$q__,true,$this->db);				
			}
		}else{
			$q__ = "INSERT INTO ".ALLCATLA." (categID,categLang,categName) 
				VALUES (".tools::__mres($categID).",'{$config->__lang}',".tools::__mres($config->categName).")";
			tools::__adodb('exec',$q__,true,$this->db);
		}	
		return $categID;	
	}
	
	public function saveEditCategory(){
		global $config;
		if(is_array($config->categName)){
			foreach ($config->categName as $lang => $kateg) {
				$q__ = "SELECT COUNT(*) FROM ".ALLCATEG." a 
					LEFT JOIN ".ALLCATLA." b ON b.categID = a.categID 
					WHERE b.categLang = '{$lang}' AND a.categID = '{$config->categID}' AND a.pageID = '{$this->pageID}'";
				$istnieje = tools::__adodb('getOne',$q__,true,$this->db);
				if($istnieje == 1){
					$q__ = "UPDATE ".ALLCATLA." SET categName = ".tools::__mres($kateg)."
						WHERE categID = ".tools::__mres($config->categID)." AND categLang = ".tools::__mres($lang);
					tools::__adodb('exec',$q__,true,$this->db);	
				}else{
					$q__ = "INSERT INTO ".ALLCATLA." (categID,categLang,categName) 
					VALUES (".tools::__mres($config->categID).",'{$lang}',".tools::__mres($kateg).")";
					tools::__adodb('exec',$q__,true,$this->db);		
				}
			}
		}else{
			$q__ = "UPDATE ".ALLCATLA." SET categName = ".tools::__mres($config->categName)."
				WHERE categID = ".tools::__mres($config->categID)." AND categLang = ".tools::__mres($config->categLang);
			tools::__adodb('exec',$q__,true,$this->db);
		}	
	}
	
	protected function usunKategorie($categID){
		$this->getListaSubkategorii($categID);
		echo $kategorie_ = explode(';',$this->subkategorie.$categID);
		if (!is_array($kategorie_)) return;
		foreach ($kategorie_ as $subCategID) {
			if(is_numeric( $subCategID)){
				$oferty_ = $this->getListaOfert($subCategID,true);
				if (!is_array($oferty_)) return;
				foreach ($oferty_ as $key => $ofertaID) {
					$this->usunOferte($subCategID,$ofertaID);
				}	
				tools::__adodb("exec","DELETE FROM ".ALLCATEG." WHERE categID = '{$subCategID}'",true,$this->db);
				tools::__adodb("exec","DELETE FROM ".ALLCATLA." WHERE categID = '{$subCategID}'",true,$this->db);				
			}
		}
	}
	
	protected function usunOferte($subCategID,$ofertaID){		
		tools::__adodb("exec","DELETE FROM ".ALLOFERT." WHERE ofertaID = '{$ofertaID}'",true,$this->db);
		tools::__adodb("exec","DELETE FROM ".ALLOFELA." WHERE ofertaID = '{$ofertaID}'",true,$this->db);
		for ($i=0;$i<=9;$i++){
			$file = "{$subCategID}_{$ofertaID}_{$i}_oferta_photo.jpg";
			$__thumbs = $this->pobierzListePlkowOferty($this->photoAllegroPath,$file);	
			if(is_array($__thumbs)) {	
				foreach ($__thumbs as $__thumb){
					$this->usunPlikiZDysku($__thumb);
				}
			}			
			$this->usunPlikiZDysku("{$this->photoAllegroPath}{$file}");				
		}
	}
	
	
	protected function pobierzListePlkowOferty($target,$file){
		global $files;
		$exceptions=array('.','..');
		$pattern="({$file}(.*).thumb$)";
		if (!$sourcedir=@opendir($target)) return false;
		$i=0;
		while(false!==($sibling=readdir($sourcedir))){
			if(!in_array($sibling,$exceptions)){
				$object=str_replace('//','/',$target.'/'.$sibling);
				if(is_dir($object)){
					$this->pobierzListePlkowOferty($object,$file);
				}
				
				if(is_file($object) && preg_match($pattern,$object)){
					$files[$i] = $object;
				}
				$i++;
			}
		}
		closedir($sourcedir);
		return $files;	
	}
	
	protected function usunPlikiZDysku($__file){
		try {
			$ret = array();
			if(file_exists($__file)){
				$result = @unlink($__file);
				$ret[0] = (!$result) ? false : true;
				$ret[1] = (!$result) ? "$__file został usunięty." : 'Error: file '.$__file. ' not deleted.';
			}else{
				$ret[0] = false;
				$ret[1] = 'Error: file '.$__file. ' not exists.';
			}
			return $ret;
		}catch ( Exception  $e ){
			$ret[0] = false;
			$ret[1] = $e->getMessage();	
			return $ret;		
		}
	}
	
	public static function listaKategoriiUstawienia($categID,$pcategID,$category,$form="Allegro/tree_edycja.tpl"){
		if (!is_array($category)) return;
		$i = 0;
		$sub = 'open';
		$czy_jest_nastepny_poziom = false;
		if ($sub){
				foreach ($category as $key1 => $rows) {
					if ( $rows['pcategID'] == $categID ){	
						$czy_jest_nastepny_poziom = true;
						if ($sub == 'open'){ 
							echo "<ul id=\"cat{$rows['categID']}\" class=\"sidemenu\">";
							$sub = 'close';				
						}
						tools::_assign('categ',$rows);

						echo "<li> ";						
						tools::_display($form);						
						AllegroModel::listaKategoriiUstawienia($rows['categID'],$rows['pcategID'],$category,$form);
						
						echo '</li>';
						$i++;
					}
				}			
			if ($sub == 'close') echo '</ul>';
		}
	}
	
	protected function getCategory($categID = null,$lang=null,$width_page=true){
		global $config;
		$width_page = ($width_page) ? " AND a.pageID = '{$this->pageID}' " : '';
		if(is_null($categID)){
			// lista wszystkich kategorii dla domyslnego jezyka
			$q__ = "SELECT a.*, b.categName, b.categLang FROM ".ALLCATEG." a 
				LEFT JOIN ".ALLCATLA." b ON b.categID = a.categID 
				WHERE b.categLang = '{$config->__lang}' {$width_page} 
				ORDER BY pcategID, a.categLp";
			return tools::__adodb('getAll',$q__,true,$this->db);
		}else{
			if  ($lang != null){
				// kategoria dla wybranego jezyka
				$q__ = "SELECT a.*, b.categName, b.categLang FROM ".ALLCATEG." a 
					LEFT JOIN ".ALLCATLA." b ON b.categID = a.categID 
					WHERE b.categLang = '{$lang}' AND a.categID = '$categID' {$width_page}";
				return tools::__adodb('getRow',$q__,true,$this->db);
			}else{
				// kategoria wiele jezykow
				$q__ = "SELECT a.*, b.categName, b.categLang FROM ".ALLCATEG." a 
					LEFT JOIN ".ALLCATLA." b ON b.categID = a.categID 
					WHERE a.categID = '$categID' {$width_page} ";
				return tools::__adodb('getAll',$q__,true,$this->db);							
			}
		}
	}

	private function getListaSubkategorii($categID){
		global $config;
		$q__ = "SELECT a.categID FROM ".ALLCATEG." a 
				LEFT JOIN ".ALLCATLA." b ON b.categID = a.categID  
				WHERE pcategID = ".tools::__mres($categID)." AND b.categLang = '{$config->__lang}' AND a.pageID = '{$this->pageID}' ";
		$__kategorie = tools::__adodb('getCol',$q__,true,$this->db);
		$this->subkategorie .= join(';',$__kategorie).';';
		foreach ($__kategorie as $categID__) {
			$this->getListaSubkategorii($categID__);
		}
	}
	
	protected function zapiszZdjeciaCategorii($categID){
		foreach ($_FILES as $fieldName => $file) {
			if ($file['size'] <= AllegroModel::maxFileWeight && $file['error'] == 0 ) {
				$up=move_uploaded_file($file['tmp_name'],  "{$this->photoAllegroPath}{$categID}_{$fieldName}.".tools::__rozszrzenie_pliku($file['name']) );
			}else{
				$up = false;
			}				
		}
	}	
	
	protected function polozenieKategorii($categID){
		global $config;
		$q__ = "SELECT a.*, b.categName, b.categLang FROM ".ALLCATEG." a 
				LEFT JOIN ".ALLCATLA." b ON b.categID = a.categID 
				WHERE b.categLang = '{$config->__lang}' AND a.categID = '$categID' ";
		$kategoria = tools::__adodb('getRow',	$q__,true,$this->db);
		$categID = (isset($kategoria['pcategID']) && $kategoria['pcategID'] != 0 ) ? $kategoria['pcategID'] : 0;
		if( $categID != 0 ) $kateg = $this->polozenieKategorii($categID);
		tools::_assign('polozenie',$kategoria);
		return $kateg.tools::_fetch("Allegro/polozenie_kategorii.tpl");
	}
	
#TODO oferty
	protected function getListaOfert($categID,$oferty_do_usuniecia=false){
		global $config;
		
		$this->subkategorie = '';
		$this->getListaSubkategorii($categID);
		$sub__ = explode(';',$this->subkategorie);
		$this->subkategorie = '(';
		foreach ($sub__ as $sub__) {	
			if (!empty($sub__)) $this->subkategorie .= "'{$sub__}'".",";			
		}
		$this->subkategorie .= "'NULL')";

		$query = "SELECT a.*,	b.* 
			FROM ".ALLOFERT." a LEFT JOIN ".ALLOFELA." b ON b.ofertaID = a.ofertaID 
			WHERE a.categID = ".tools::__mres($categID)." AND b.ofertaLang = '{$config->__lang}' 
				OR  a.categID IN ".$this->subkategorie." AND b.ofertaLang = '{$config->__lang}'  
			ORDER BY a.ofertaDate  DESC ";
		if($oferty_do_usuniecia) $query = "SELECT a.ofertaID FROM ".ALLOFERT." a 
			WHERE a.categID = ".tools::__mres($categID)." 
			OR  a.categID IN ".$this->subkategorie;
		if($oferty_do_usuniecia) return tools::__adodb('getCol',$query,true,$this->db);
		return tools::__adodb('getAll',$query,true,$this->db);		
	}
	
	protected function getListaOfertWyszukiwarka(){
		global $config;
		
		$find = strtoupper($config->wyszukaj);
		$find = strip_tags($config->wyszukaj);
		$find = trim ($config->wyszukaj);

		
		$query = "SELECT a.*,	b.* 
			FROM ".ALLOFERT." a LEFT JOIN ".ALLOFELA." b ON b.ofertaID = a.ofertaID 
			LEFT JOIN ".ALLCATEG." c ON a.categID = c.categID 
			WHERE b.ofertaLang = '{$config->__lang}' AND upper(b.ofertaName) LIKE'%$find%' AND c.pageID = '{$this->pageID}'  
				OR b.ofertaLang = '{$config->__lang}' AND  upper(b.ofertaLid) LIKE'%$find%' AND c.pageID = '{$this->pageID}' 
				OR b.ofertaLang = '{$config->__lang}' AND  upper(b.ofertaOpis) LIKE'%$find%' AND c.pageID = '{$this->pageID}' 
			ORDER BY a.ofertaDate  DESC ";
		return tools::__adodb('getAll',$query,true,$this->db);		
	}	
	
	protected function getListaOfertPromocyjnych($limit_=0,$ofertaID = null){
		global $config;
		$limit = ($limit_ == 0) ? "" : "LIMIT $limit_";
		$notin = (!is_null($ofertaID)) ? " AND a.ofertaID NOT IN ($ofertaID)" : "";
		$query = "SELECT a.*,	b.*
			FROM ".ALLOFERT." a LEFT JOIN ".ALLOFELA." b ON b.ofertaID = a.ofertaID 
			LEFT JOIN ".ALLCATEG." c ON a.categID = c.categID 
			WHERE a.ofertaSpec = 1 AND c.pageID = '{$this->pageID}'  AND b.ofertaLang = '{$config->__lang}' {$notin} 
			ORDER BY a.ofertaDate  DESC $limit";
		return tools::__adodb('getAll',$query,true,$this->db);		
	}
	
	protected function getOferta($ofertaID,$lang_=null){
		global $config;
		$lang = (is_null($lang_)) ? $config->__lang : $lang_;
		
		$query = "SELECT COUNT(*) 
			FROM ".ALLOFERT." a LEFT JOIN ".ALLOFELA." b ON b.ofertaID = a.ofertaID 
			WHERE a.ofertaID = ".tools::__mres($ofertaID)." AND  b.ofertaLang = '{$lang}'"; 
		$istnieje = tools::__adodb('getOne',$query,true,$this->db);
		
		if ($istnieje == 1){		
			$query = "SELECT a.*,	b.* 
				FROM ".ALLOFERT." a LEFT JOIN ".ALLOFELA." b ON b.ofertaID = a.ofertaID 
				WHERE a.ofertaID = ".tools::__mres($ofertaID)." AND  b.ofertaLang = '{$lang}'"; 
			return tools::__adodb('getRow',$query,true,$this->db);
		}else{
			$query = "SELECT a.*
				FROM ".ALLOFERT." a 
				WHERE a.ofertaID = ".tools::__mres($ofertaID);
			$oferta =  tools::__adodb('getRow',$query,true,$this->db);
			$oferta['ofertaLang'] = $lang;
			return $oferta;
		}
	}
	
	protected function zapiszNowaOferte(){
		global $config;
		$q__ = "INSERT INTO ".ALLOFERT." ( categID, ofertaID, ofertaDate, ofertaSpec, ofertaLock ) 
			VALUES (".tools::__mres($config->categID).",NULL,'".date('Y-m-d H:i:s')."',
			".tools::__mres($config->ofertaSpec).",".tools::__mres($config->ofertaLock).")";
		tools::__adodb('exec',$q__,true,$this->db);	
		
		$ofertaID = $this->db->lastInsertId();
		$q__ = "INSERT INTO ".ALLOFELA." ( ofertaID, ofertaLang, ofertaName, ofertaLid, ofertaOpis,
			ofertaInfo, ofertaDost, ofertaUrl, ofertaTags,ofertaOpisZ0,ofertaOpisZ1,ofertaOpisZ2,ofertaOpisZ3,ofertaOpisZ4,
			ofertaOpisZ5,ofertaOpisZ6,ofertaOpisZ7,ofertaOpisZ8,ofertaOpisZ9 ) 
			VALUES ( $ofertaID,".tools::__mres($config->__lang).",".tools::__mres($config->ofertaName,true)."
			,".tools::__mres($config->ofertaLid,true).",".tools::__mres($config->ofertaOpis,true)."
			,".tools::__mres($config->ofertaInfo,true).",".tools::__mres($config->ofertaDost,true)."
			,".tools::__mres($config->ofertaUrl,true).",".tools::__mres($config->ofertaTags,true)."
			,".tools::__mres($config->ofertaOpisZ0,true).",".tools::__mres($config->ofertaOpisZ1,true)."
			,".tools::__mres($config->ofertaOpisZ2,true).",".tools::__mres($config->ofertaOpisZ3,true)."
			,".tools::__mres($config->ofertaOpisZ4,true).",".tools::__mres($config->ofertaOpisZ5,true)."
			,".tools::__mres($config->ofertaOpisZ6,true).",".tools::__mres($config->ofertaOpisZ7,true)."	
			,".tools::__mres($config->ofertaOpisZ8,true).",".tools::__mres($config->ofertaOpisZ9,true)."	
			)";
		tools::__adodb('exec',$q__,true,$this->db);			
		return $ofertaID;
	}
	
	protected function zapiszEdytowanaOferte(){
		global $config;
		
		$query = "SELECT COUNT(*) 
			FROM ".ALLOFERT." a LEFT JOIN ".ALLOFELA." b ON b.ofertaID = a.ofertaID 
			WHERE a.ofertaID = ".tools::__mres($config->ofertaID)." AND  b.ofertaLang = '{$config->ofertaLang}'"; 
		$istnieje = tools::__adodb('getOne',$query,true,$this->db);
		
		if ($istnieje == 1){
			$q__ = "UPDATE ".ALLOFERT." SET 
				ofertaDate = '".date('Y-m-d H:i:s')."',
				ofertaSpec = ".tools::__mres($config->ofertaSpec).", 
				ofertaLock = ".tools::__mres($config->ofertaLock).",
				ofertaPlikiLoad = ".tools::__mres($config->ofertaPlikiLoad)."
				WHERE ofertaID = ".tools::__mres($config->ofertaID);
			tools::__adodb('exec',$q__,true,$this->db);
			
			$q__ = "UPDATE ".ALLOFELA." SET ofertaName = ".tools::__mres($config->ofertaName,true).",
				ofertaLid = ".tools::__mres($config->ofertaLid,true).",
				ofertaOpis = ".tools::__mres($config->ofertaOpis,true).",
				ofertaInfo = ".tools::__mres($config->ofertaInfo,true).",
				ofertaDost = ".tools::__mres($config->ofertaDost,true).",
				ofertaUrl = ".tools::__mres($config->ofertaUrl,true).",
				ofertaTags = ".tools::__mres($config->ofertaTags,true).",
				ofertaOpisZ0 = ".tools::__mres($config->ofertaOpisZ0,true).",
				ofertaOpisZ1 = ".tools::__mres($config->ofertaOpisZ1,true).",
				ofertaOpisZ2 = ".tools::__mres($config->ofertaOpisZ2,true).",
				ofertaOpisZ3 = ".tools::__mres($config->ofertaOpisZ3,true).",
				ofertaOpisZ4 = ".tools::__mres($config->ofertaOpisZ4,true).",
				ofertaOpisZ5 = ".tools::__mres($config->ofertaOpisZ5,true).",
				ofertaOpisZ6 = ".tools::__mres($config->ofertaOpisZ6,true).",
				ofertaOpisZ7 = ".tools::__mres($config->ofertaOpisZ7,true).",
				ofertaOpisZ8 = ".tools::__mres($config->ofertaOpisZ8,true).",
				ofertaOpisZ9 = ".tools::__mres($config->ofertaOpisZ9,true)."
				WHERE ofertaID = ".tools::__mres($config->ofertaID)." 
					AND ofertaLang = ".tools::__mres($config->ofertaLang);
			tools::__adodb('exec',$q__,true,$this->db);
		}else{
			$ofertaID = $config->ofertaID;
			$q__ = "INSERT INTO ".ALLOFELA." ( ofertaID, ofertaLang, ofertaName, ofertaLid, ofertaOpis,
				ofertaInfo, ofertaDost, ofertaUrl, ofertaTags,ofertaOpisZ0,ofertaOpisZ1,ofertaOpisZ2,ofertaOpisZ3,ofertaOpisZ4,
				ofertaOpisZ5,ofertaOpisZ6,ofertaOpisZ7,ofertaOpisZ8,ofertaOpisZ9 ) 
				VALUES ( $ofertaID,".tools::__mres($config->ofertaLang).",".tools::__mres($config->ofertaName,true)."
				,".tools::__mres($config->ofertaLid,true).",".tools::__mres($config->ofertaOpis,true)."
				,".tools::__mres($config->ofertaInfo,true).",".tools::__mres($config->ofertaDost,true)."
				,".tools::__mres($config->ofertaUrl,true).",".tools::__mres($config->ofertaTags,true)."
				,".tools::__mres($config->ofertaOpisZ0,true).",".tools::__mres($config->ofertaOpisZ1,true)."
				,".tools::__mres($config->ofertaOpisZ2,true).",".tools::__mres($config->ofertaOpisZ3,true)."
				,".tools::__mres($config->ofertaOpisZ4,true).",".tools::__mres($config->ofertaOpisZ5,true)."
				,".tools::__mres($config->ofertaOpisZ6,true).",".tools::__mres($config->ofertaOpisZ7,true)."	
				,".tools::__mres($config->ofertaOpisZ8,true).",".tools::__mres($config->ofertaOpisZ9,true)."	
				)";
			tools::__adodb('exec',$q__,true,$this->db);
		}
	}
	
	/**
	 * zapisuje zdjęcia oferty
	 * struktura nazwy pliku:
	 * cateID_ofertaID_[0..9]_oferta_photo.ext
	 * 
	 * @param $ofertaID
	 * @return unknown_type
	 */
	protected function zapiszZdjeciaOferty($ofertaID){
		global $config;
		foreach ($_FILES as $fieldName => $file) {
			if ($file['size'] <= AllegroModel::maxFileWeight && $file['error'] == 0 ) {	
				// usuwam thumbs dla nowego zdjecia
				$file__ = "{$config->categID}_{$ofertaID}_{$fieldName}";
				$files = tools::get_folders_files($this->photoAllegroPath);
				foreach ($files[0]['files'] as  $path_ ) {
					$file_name = str_replace($this->photoAllegroPath,'',$path_['nazwa']);
					$file_ = explode('.',$file_name);
					if ($file_[0] == $file__){
						tools::_delete_file($this->photoAllegroPath."{$file_name}");
					}
				}									
				$up=move_uploaded_file($file['tmp_name'],  "{$this->photoAllegroPath}{$config->categID}_{$ofertaID}_{$fieldName}.jpg"/*.tools::__rozszrzenie_pliku($file['name'])*/ );
			}else{
				$up = false;
			}				
		}
	}
#TODO settings
	protected function saveSettingsAllegro(){
		global $config;
		foreach ($config->settings_allegro as $id => $wartosc) {
			$id__ = tools::__adodb('getOne',"SELECT id  FROM ".ALLOFESE." WHERE id = ".tools::__mres($id),true,$this->db); 
			if($id == $id__){
				tools::__adodb("exec","UPDATE ".ALLOFESE." SET wartosc = ".tools::__mres($wartosc)." WHERE id = ".tools::__mres($id),true,$this->db);
			}else{
				tools::__adodb("exec","INSERT INTO ".ALLOFESE." (id, wartosc) VALUES (".tools::__mres($id).",".tools::__mres($wartosc).");",true,$this->db);
			}
		}
	}
		
	protected function AllegroSettings(){	
		$q__ = "SELECT id, wartosc FROM ".ALLOFESE;
		return tools::__adodb('getAssoc',$q__,true,$this->db);
	}

}